package joindemo.aop;

import joindemo.annotation.CheckDeleteMessage;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class CheckDeleteMessageInterceptor {

    @Before("@annotation(checkDeleteMessage)")
    public void checkDeleteMessage(JoinPoint joinPoint, CheckDeleteMessage checkDeleteMessage) {

//        log.info("进入检查数据删除的切面");
//        //获取用户id
//        Long userId = StpUtil.getLoginIdAsLong();
//        User user = Db.lambdaQuery(User.class).eq(User::getUserId, userId).one();
//        Object[] args = joinPoint.getArgs();
//        Long dataId = (Long) args[0];
//        Message message = Db.lambdaQuery(Message.class).eq(Message::getArticleId, dataId).one();
//        Long messageUserId=message.getUserId();
//        if(!userId.equals(messageUserId)) {
//            log.warn("用户没有权限删除此数据");
//            throw new ServiceException(HttpStatusEnum.UNAUTHORIZED);
//        }
    }
}
